package com.tanhua.server.controller;

import com.tanhua.server.service.DashboardService;
import com.tanhua.server.vo.SummaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("dashboard")
public class DashboardController {

    @Autowired
    private DashboardService dashboardService;

    /**
     * 新增、活跃用户、次日留存率
     * @param type 类型
     * @param sd 开始时间
     * @param ed 结束时间
     * @return
     */
    @GetMapping("users")
    public ResponseEntity queryUsers(@RequestParam("type") String type,
                                     @RequestParam("sd") Long sd,
                                     @RequestParam("ed") Long ed){
        //调用server查询数据
       Map<String,Object> map= dashboardService.queryUsers(type, sd, ed);
        return ResponseEntity.ok(map);
    }

    /**
     * 概要统计信息
     * @return
     */
    @GetMapping("summary")
    public ResponseEntity querySummary(){
        //调用service查询数据
        SummaryVo summaryVo= dashboardService.querySummary();
        return ResponseEntity.ok(summaryVo);
    }

    @GetMapping("distribution")
    public ResponseEntity distribution(Long sd, Long ed) {
        Map<String,Object> resultMap = dashboardService.queryDistribution(sd,ed);

        return ResponseEntity.ok(resultMap);
    }


}
